/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package com.workcell.workdata.im.model.response;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PaginationEntity<T>  extends ResponseEntity<List<T>> {

	/**
	 * 数据总条数
	 */
	private static final String KEY_COUNT = "count";

	/**
	 * 数据总页数
	 */
	private static final String KEY_COUNT_PAGE = "countPage";

	/**
	 * 每页几条数据
	 */
	private static final String KEY_PAGE_SIZE = "size";

	/**
	 * 当前第几页
	 */
	private static final String KEY_CURRENT_PAGE = "currentPage";

	private final Map<String,Number> page = new HashMap<>();

	private List<T> data;

	public Map<String, Number> getPage() {
		return page;
	}

	@Override
	public List<T> getData() {
		return data;
	}

	@Override
	public void setData(List<T> data) {
		this.data = data;
	}

	public static <T> PaginationEntity<T> make(org.springframework.data.domain.Page<T> dto) {
		PaginationEntity<T> result = new PaginationEntity<>();
		result.page.put(KEY_COUNT,dto.getTotalElements());
		result.page.put(KEY_COUNT_PAGE,dto.getTotalPages());
		result.page.put(KEY_PAGE_SIZE,dto.getSize());
		result.page.put(KEY_CURRENT_PAGE,dto.getNumber());
		result.setData(dto.getContent());
		return result;
	}

}
